import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = (data, details, saleProformaPartDetails) => {
    //增加判断必填字段
    const emptyErrors = [];
    if(!data || !data.brandId)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.brandId',
            defaultMessage: '品牌'
        }));
    if(!data || !data.dealerId)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.dealerId',
            defaultMessage: '总代'
        }));
    if(!data || !data.piCode)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.piCode',
            defaultMessage: '发票号'
        }));
    if(!data || !data.productionMonth)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.productionMonth',
            defaultMessage: '产品月份'
        }));
    if(!data || !data.title)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.title',
            defaultMessage: '标题'
        }));
    if(!data || !data.cargoDescription)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.cargoDescription',
            defaultMessage: '货描'
        }));
    if(!data || !data.model)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.model',
            defaultMessage: '车型编号'
        }));
    if(!data || !data.currency)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.currency',
            defaultMessage: '币种'
        }));
    if(!data || !data.salesOrderPriceTerms)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.salesOrderPriceTerms',
            defaultMessage: '价格条款'
        }));
    if(!data || !data.paymentType)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.paymentType',
            defaultMessage: '付款方式'
        }));
    if(!data || !data.deliveryTerms)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.deliveryTerms',
            defaultMessage: '运输方式'
        }));
    if(!data || !data.bankId)
        emptyErrors.push(formatMessage({
            id: 'validator.empty.bankId',
            defaultMessage: '银行名称'
        }));
    if(emptyErrors.length > 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.required',
            defaultMessage: '必填！'
        })}`);
        return false;
    }
    if(details.length <= 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.detailRequired',
            defaultMessage: '清单不能为空'
        })}`);
        return false;
    }
    if(saleProformaPartDetails <= 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.detailRequired',
            defaultMessage: '清单不能为空'
        })}`);
        return false;
    }
    if(details.some(d => !d.placement)) {
        message.warning(formatMessage({
            id: 'validator.message.placement',
            defaultMessage: '配置必填'
        }));
        return false;
    }
    if(details.some(d => !d.quantity)) {
        message.warning(formatMessage({
            id: 'validator.message.quantity',
            defaultMessage: '数量必填'
        }));
        return false;
    }
    if(details.some(d => !d.price)) {
        message.warning(formatMessage({
            id: 'validator.message.price',
            defaultMessage: '单价'
        }));
        return false;
    }
    return true;
};

export const confirmValidator = data => {
    //增加判断必填字段
    const emptyErrors = [];
    if(data.attachments.length <= 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.fileRequired',
            defaultMessage: '附件不能为空'
        })}`);
        return false;
    }
    return true;
};

